//
//  LogoNumberView.m
//  KeleAppProject
//
//  Created by Cen Zhou on 2018/1/15.
//  Copyright © 2018年 Cen Zhou. All rights reserved.
//

#import "LogoNumberView.h"

@interface LogoNumberView()

@property (nonatomic, strong) UIImageView *flgImageView;
@property (nonatomic, strong) UILabel *accountLb;
@property (nonatomic, copy) NSString *imageName;
@end

@implementation LogoNumberView


- (void)setValuesWithDataDic:(NSDictionary *)dataDic{
    self.imageName = dataDic[@"imageStr"];
    UIView *contentView = [[UIView alloc]init];
    contentView.backgroundColor = [UIColor clearColor];
    UITapGestureRecognizer *tapContent = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
    [contentView addGestureRecognizer:tapContent];
    [self addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    UIImageView *imageView_flg = [[UIImageView alloc]init];
    imageView_flg.contentMode = UIViewContentModeScaleAspectFit;
    imageView_flg.image = [UIImage imageNamed:dataDic[@"imageStr"]];
    [contentView addSubview:imageView_flg];
    self.flgImageView = imageView_flg;
    [imageView_flg mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(contentView);
        make.top.equalTo(contentView);
        make.left.equalTo(contentView);
        make.width.height.mas_equalTo(20*WIDTH);
    }];
    
    UILabel *numberCount = [[UILabel alloc]init];
    numberCount.text = dataDic[@"title"];
    numberCount.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12*WIDTH];
    numberCount.textColor = KLColor_B7;
    [contentView addSubview:numberCount];
    self.accountLb = numberCount;
    [numberCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(imageView_flg);
        make.left.equalTo(imageView_flg.mas_right).offset(6*WIDTH);
    }];
}


- (void)tapClick:(UITapGestureRecognizer *)tap{
    // 图片数字颜色要变
    self.flgImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@_pre",self.imageName]];
    self.accountLb.textColor = KLColor_B11;
    // 加动画
    [self addAnimationWithItems:tap.view];
    if (self.signalDelegate) {
        [self.signalDelegate sendNext:nil];
    }
}

// 动画
- (void)addAnimationWithItems:(UIView *)view{
            //添加动画
        //放大效果，并回到原位
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        //速度控制函数，控制动画运行的节奏
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        animation.duration = 0.5;       //执行时间
        animation.repeatCount = 1;      //执行次数
        //        animation.autoreverses = YES;    //完成动画后会回到执行动画之前的状态
        animation.fromValue = [NSNumber numberWithFloat:0.7];   //初始伸缩倍数
        animation.toValue = [NSNumber numberWithFloat:1.3];     //结束伸缩倍数
        [[view layer] addAnimation:animation forKey:nil];
    
}



- (void)setOriginValuesWithDataDic:(NSDictionary *)dataDic{
    self.imageName = dataDic[@"imageStr"];
    UIView *contentView = [[UIView alloc]init];
    contentView.backgroundColor = [UIColor clearColor];
    UITapGestureRecognizer *tapContent = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(click)];
    [contentView addGestureRecognizer:tapContent];
    [self addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    UIImageView *imageView_flg = [[UIImageView alloc]init];
    imageView_flg.contentMode = UIViewContentModeScaleAspectFit;
    imageView_flg.image = [UIImage imageNamed:dataDic[@"imageStr"]];
    [contentView addSubview:imageView_flg];
    self.flgImageView = imageView_flg;
    [imageView_flg mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.centerY.equalTo(contentView);
        make.top.equalTo(contentView);
        make.left.equalTo(contentView);
        make.width.height.mas_equalTo(20*WIDTH);
    }];
    
    UILabel *numberCount = [[UILabel alloc]init];
    numberCount.text = dataDic[@"title"];
    numberCount.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12*WIDTH];
    numberCount.textColor = KLColor_B7;
    [contentView addSubview:numberCount];
    self.accountLb = numberCount;
    [numberCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(imageView_flg);
        make.left.equalTo(imageView_flg.mas_right).offset(6*WIDTH);
    }];
    
}

- (void)setImageValuesWithDataDic:(NSDictionary *)dataDic{
    self.imageName = dataDic[@"imageStr"];
    UIView *contentView = [[UIView alloc]init];
    contentView.backgroundColor = [UIColor clearColor];
    contentView.tag = [dataDic[@"tag"] integerValue] + 100;
    UITapGestureRecognizer *tapContent = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClickImage:)];
    [contentView addGestureRecognizer:tapContent];
    [self addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    UIImageView *imageView_flg = [[UIImageView alloc]init];
    imageView_flg.contentMode = UIViewContentModeScaleAspectFit;
    imageView_flg.image = [UIImage imageNamed:dataDic[@"imageStr"]];
    [contentView addSubview:imageView_flg];
    self.flgImageView = imageView_flg;
    [imageView_flg mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.centerY.equalTo(contentView);
        make.top.equalTo(contentView);
        make.left.equalTo(contentView);
        make.width.height.mas_equalTo([dataDic[@"size"] floatValue]*WIDTH);
    }];
}

- (void)tapClickImage:(UITapGestureRecognizer *)tap{
    // 图片数字颜色要变
    // 加动画
    if (tap.view.tag == 100) {
        self.flgImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@_pre",self.imageName]];
        [self addAnimationWithItems:tap.view];
    }
    if (self.signalDelegate) {
        [self.signalDelegate sendNext:nil];
    }
}


- (void)click{
    if (self.signalDelegate) {
        [self.signalDelegate sendNext:nil];
    }
}




@end
